#include "game_http.h"
#include <strings.h>

using namespace CGame::Httpd;


const char* MediaType::TEXT_CSS_VALUE                        = "text/css";
const char* MediaType::TEXT_CSS_UTF8_VALUE                   = "text/css; charset=utf-8";
const char* MediaType::APPLICATION_FORM_URLENCODED_VALUE     = "application/x-www-form-urlencoded";
const char* MediaType::MULTIPART_FORM_DATA_VALUE             = "multipart/form-data";
const char* MediaType::APPLICATION_JAVASCRIPT_VALUE          = "application/javascript";
const char* MediaType::APPLICATION_JAVASCRIPT_UTF8_VALUE     = "application/javascript; charset=utf-8";
const char* MediaType::APPLICATION_JSON_VALUE                = "application/json";
const char* MediaType::APPLICATION_JSON_UTF8_VALUE           = "application/json; charset=utf-8";
const char* MediaType::APPLICATION_OCTET_STREAM_VALUE        = "application/octet-stream";
const char* MediaType::TEXT_HTML_VALUE                       = "text/html";
const char* MediaType::TEXT_HTML_UTF8_VALUE                  = "text/html; charset=utf-8";
const char* MediaType::TEXT_XML_VALUE                        = "text/xml";
const char* MediaType::IMAGE_JPEG_VALUE                      = "image/jpeg";
const char* MediaType::IMAGE_PNG_VALUE                       = "image/png";
const char* MediaType::IMAGE_GIF_VALUE                       = "image/gif";
const char* MediaType::IMAGE_SVG_VALUE                       = "image/svg+xml";
const char* MediaType::FONT_WOFF2_VALUE                      = "font/woff2";
const char* MediaType::FONT_TTF_VALUE                        = "font/truetype";

Status_t Status::BADREQUEST                                  = {400,"400 Bad Request"};
Status_t Status::FORBIDDEN                                   = {403,"403 Forbidden"};
Status_t Status::NOTFOUND                                    = {404,"404 Not Found"};
Status_t Status::BADMETHOD                                   = {405,"405 Not Allowed"};
Status_t Status::ENTITYTOOLARGE                              = {413,"413 Request Entity Too Large"};
Status_t Status::INTERNAL                                    = {500,"500 Internal Server Error"};
Status_t Status::NOTIMPLEMENTED                              = {501,"501 Not Implemented"};
Status_t Status::SERVUNAVAIL                                 = {503,"503 Service Temporarily Unavailable"};




const char* MediaType::getContentType(const char *ext){
  if(0 == strcasecmp(ext,".jpg") || 0 == strcasecmp(ext,".jpeg")){
    return IMAGE_JPEG_VALUE;
  }

  if(0 == strcasecmp(ext,".png")){
    return IMAGE_PNG_VALUE;
  }

  if(0 == strcasecmp(ext,".gif")){
    return IMAGE_GIF_VALUE;
  }

  if(0 == strcasecmp(ext,".js")){
    return APPLICATION_JAVASCRIPT_VALUE;
  }

  if(0 == strcasecmp(ext,".css")){
    return TEXT_CSS_VALUE;
  }

  if(0 == strcasecmp(ext,".html")){
    return TEXT_HTML_VALUE;
  }

  if(0 == strcasecmp(ext,".svg")){
    return IMAGE_SVG_VALUE;
  }

  if(0 == strcasecmp(ext,".ttf")){
    return FONT_TTF_VALUE;
  }

  if(0 == strcasecmp(ext,".woff2")){
    return FONT_WOFF2_VALUE;
  }

  return APPLICATION_OCTET_STREAM_VALUE;
}












BOOL UserAgent::isChrome(const char *ua)
{
  std::string str{ua};
  return std::string::npos != str.find("Chrome") ? TRUE : FALSE;
}



